class CountersController < ApplicationController
  def index
  end

  def get_data
    @counters = Counter.find(:all)
    render :json => @counters.to_jqgrid_json([:id,:code,:so,:guihao,:fengtiaohao,:cbm],1,2,10)
  end

  def get_editor
    render :text => (Counter.find_by_id(params[:id]).cbm)
  end

  def edit
    @counter = Counter.find(params[:id])
    respond_to do |format|
      format.html { render :layout=>false  } # edit.html.erb
      format.xml  { render :xml => @counter }
    end
  end

  def update
    puts params[:counter][:id]
    @counter = Counter.find(params[:counter][:id])
    if @counter.update_attributes(params[:counter])
      #format.html { redirect_to(@counter, :notice => 'Test was successfully updated.') }
      puts "counter updated successfully"
      respond_to do |want|
        want.js {render :text=>"数据更新成功!<script>jQuery('#list2').trigger('reloadGrid');</script>"}
        #render :partial => "result"
      end
      
    else
        want.js {render :text=>"数据更新失败!"}
    end
  end

end
